<div class="layui-form" lay-filter="layuiadmin-form-tags" id="layuiadmin-form">
    <div class="layui-form-item">
        <label class="layui-form-label">类型名</label>
        <div class="layui-input-block">
            <script type="text/html" template>
            <input type="text" name="title" value="{{ d.params.title || '' }}" lay-verify="required"
                       placeholder="请输入..." autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片限制大小</label>
        <div class="layui-input-inline append-select">
        </div>
    </div>
    <div class="layui-form-item limit_policy layui-hide">
        <label class="layui-form-label">限制策略</label>
        <div class="layui-input-block">
            <script type="text/html" template>
                <textarea name="limit_policy" class="layui-textarea">{{ d.params.limit_policy || '' }}</textarea>
            </script>
            <span class="layui-form-mid layui-word-aux">请输入宽和高 例如：320,400 代表320的宽400的高</span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="layuiadmin-submit" value="确认" class="layui-btn">
        </div>
    </div>
</div>
<style>
    #layuiadmin-form .layui-form-label{width:100px;}
    #layuiadmin-form .layui-input-block{margin-left: 130px;}
</style>
<script>
    var $ = layui.$;
    layui.use(['form', 'helper', 'laytpl', 'upload', 'element'], function () {
        var form = layui.form,
            setter = layui.setter,
            helper = layui.helper;
        form.render('select');
        let url = '/app/ad-type/edit';
        let params = window.params;
        if (params){
            url += '?id=' + params.id;
            showPolicy(params.limit_size);
        }

        form.on('select(limit_size)' , function(res){
            let val = res.value;
            showPolicy(val)
        })
        helper.requestRenderSelect(url , 'limit_size' , '.append-select' , form , {
            filter : 'limit_size'
        })
    });

    function showPolicy(val){
        switch (val) {
            case '1' :
                $('.limit_policy').removeClass('layui-hide');
                break;
            default:
                $('.limit_policy').addClass('layui-hide');
                break;
        }
    }
</script>